using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace _512396_01
{
    public partial class TwoStateButton:UserControl
    {
        #region Attributes
        
        private Bitmap _hoverPic;// the index of image is showed when mouse move
        private Bitmap _normalPic;// the index image is showed at the normal state
        private Bitmap _curPic;// the index of the current image 
        #endregion

        #region Properties
        public Bitmap HoverPicture
        {
            get
            {
                return _hoverPic;
            }
            set
            {
                if (value == null)
                    return;

                _hoverPic = value;
                this.Size = new Size(value.Width, value.Height);
            }
        }

        public Bitmap NormalPicture
        {
            get { return _normalPic; }
            set
            {
                if (value == null)
                    return;

                _normalPic = value;
                this.Size = new Size(value.Width, value.Height);
                _curPic = value;
            }
        }
        #endregion

        public TwoStateButton()
        {
            _hoverPic = null;
            _normalPic = null;
            _curPic = null;

            InitializeComponent();
        }

        private bool IsEmpty()
        {
            return (_curPic == null);
        }

        private void TwoStateButton_Paint(object sender, PaintEventArgs e)
        {
            if(!IsEmpty())
            {
                
                Graphics g = e.Graphics;

                g.DrawImage(_curPic, 0, 0);
            }
            
        }        

        private void TwoStateButton_MouseUp(object sender, MouseEventArgs e)
        {
            _curPic = NormalPicture;

            Invalidate();
        }

        private void TwoStateButton_MouseMove(object sender, MouseEventArgs e)
        {
    //        _curPic = HoverPicture;

     //       Invalidate();
        }

        private void TwoStateButton_MouseDown(object sender, MouseEventArgs e)
        {
            _curPic = HoverPicture;

            Invalidate();
        }



       
    }
}
